package br.pucrs.lognplay.vo;

import java.util.Date;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class Log {

	public enum Severity {
		EMERGENCY("Emergency"), ALERT("Alert"), CRITICAL("Critical"), ERROR("Error"), WARNING("Warning"), NOTICE("Notice"), INFORMATIONAL("Informational"), DEBUG("Debug");

		private final String label;

		Severity(String label) {
			this.label = label;
		}

		public String getLabel() {
			return label;
		}
	}

	private Date timestamp;

	private String message;

	private String severity;

	private String hostname;

	private String facility;

	public Date getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getSeverity() {
		return severity;
	}

	public void setSeverity(String severity) {
		this.severity = severity;
	}

	public String getHostname() {
		return hostname;
	}

	public void setHostname(String hostname) {
		this.hostname = hostname;
	}

	public String getFacility() {
		return facility;
	}

	public void setFacility(String facility) {
		this.facility = facility;
	}

	public boolean equals(Object object) {
		if (object == null) {
			return false;
		}

		if (object == this) {
			return true;
		}

		Class<?> objectClass = object.getClass();

		if (!objectClass.equals(getClass())) {
			return false;
		}

		Log log = (Log) object;

		EqualsBuilder equalsBuilder = new EqualsBuilder();
		equalsBuilder.append(log.getTimestamp(), getTimestamp());
		equalsBuilder.append(log.getMessage(), getMessage());
		equalsBuilder.append(log.getSeverity(), getSeverity());
		equalsBuilder.append(log.getHostname(), getHostname());
		equalsBuilder.append(log.getFacility(), getFacility());
		return equalsBuilder.isEquals();
	}

	public int hashCode() {
		HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
		hashCodeBuilder.append(getTimestamp());
		hashCodeBuilder.append(getMessage());
		hashCodeBuilder.append(getSeverity());
		hashCodeBuilder.append(getHostname());
		hashCodeBuilder.append(getFacility());
		return hashCodeBuilder.toHashCode();
	}

	public String toString() {
		ToStringBuilder toStringBuilder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		toStringBuilder.append("timestamp", getTimestamp());
		toStringBuilder.append("message", getMessage());
		toStringBuilder.append("severity", getSeverity());
		toStringBuilder.append("hostname", getHostname());
		toStringBuilder.append("facility", getFacility());
		return toStringBuilder.toString();
	}
}
